<div class="history box3"><{if $setting.title}><div class="hd"><h3><{$setting.title}></h3></div><{/if}><div class="bd" id="box_<{$widgets_id}>"><ul class="p-list clearfix"></ul></div></div>
<script>
    withBrowserStore(function(browserStore){
        var box=$('box_<{$widgets_id}>');
        browserStore.get('history', function(rs) {
            rs = JSON.decode(rs);
            var min = 1;
            if (!rs || rs.length <= min) return box.hide();
            var html='';
            var template = '<li class="goods-item clearfix {force}">';
                template+= '<div class="goods-pic">';
                template+= '<a href="<{link app=b2c ctl=site_product act=index arg0="{goodsId}"}>" target="_blank" title="{goodsName}" data-gid="{goodsId}"><img src="{goodsImg}" alt="{goodsName}" /></a>'.replace('index-','');
                template+= '</div>';
                template+='<div class="goods-info">';
                template+='<h3 class="goods-name"><a href="<{link app=b2c ctl=site_product act=index arg0="{goodsId}"}>" target="_blank" title="{goodsName}">{goodsName}</a></h3>'.replace('index-','');
                template+= '<div class="goods-price"><ins class="price">{price}</ins></div>';
				template+= '</div>';
                template+= '</li>';

            var max=Math.min(rs.length,<{$setting.max|default:5}>);

            rs.each(function(goods,index){
                if(index >= min && index <= max){
                    goods['force'] = 'fore'+index;
                    html += template.substitute(goods);
                }
            });

            box.getElement('ul').innerHTML = html;

            box.getElements('.goods-pic a').each(function(item) {
                var img = item.getElement('img');
                img.zoomImg(<{$setting.width|default:'80'}>,<{$setting.height|default:'80'}>);
                img.onerror = function(){
                    imgRequest(item, img, rs, min, max);
                }
                if (!img.get('src')) {
                    imgRequest(item, img, rs, min, max);
                }
            });
        });

        function imgRequest(el, img, rs, min, max) {
            var gid = el.get('data-gid');
            new Request.JSON({
                url: "<{link app=b2c ctl=site_product act=picsJson}>",
                onComplete: function(data) {
                    new Asset.image(data, {
                        onload: function() {
                            img.src = data;
                            img.zoomImg(<{$setting.width|default:'80'}>,<{$setting.height|default:'80'}>);
                        },
                        onerror: function() {
                            el.set('text', '<{t}>图片加载失败<{/t}>');
                        }
                    });

                    rs.map(function(goods, index) {
                        if (index >= min && index <= max && goods['goodsId'] == gid) return goods['goodsImg'] = data;
                    });

                    browserStore.set('history', JSON.encode(rs));
                }
            }).get({'gids': gid});
        }
    });
</script>